package com.andrew.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.andrew.entity.Cart;
import com.andrew.entity.Customer;
import com.andrew.service.CartService;
import com.andrew.service.impl.CartServiceImpl;

public class DeleteOneCartDetail extends HttpServlet {

	private CartService cartService=new CartServiceImpl(); 
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		//设置编码
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		
		int bookId=Integer.parseInt(req.getParameter("bookId"));
		Cart cart=(Cart)req.getSession().getAttribute("cart");
		
		try {
			int flag=cartService.deleteoneCartDetail(bookId, cart);
			if (flag>0) {
				resp.getWriter().write("success");
			}else {
				resp.getWriter().write("false");
			}
		} catch (SQLException e) {
			resp.getWriter().write("false");
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doGet(req, resp);
	}
}
